import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * An enemy that will jump it gets to certain position.
 * 
 * @author Manuel Nava
 * @version 1.0
 */
public class Frog extends Enemy
{
    private boolean jumping;
    private int velY;
    private boolean vulnerable;
    private GreenfootImage stand;
    private GreenfootImage jump;
    
    /**
     * The constructor set the variables to false and loads the images to use.
     */
    public Frog()
    {
        jumping=false;
        vulnerable=false;
        stand=new GreenfootImage("rana-stand.png");
        jump=new GreenfootImage("rana-jump2.png");
    }
    
    /**
     * The method act calls the superclass method move, so it verifys if the object as got to a certain position
     * and changes certain variables values.
     */
    public void act() 
    {
        super.move();
        if(getX()<=250&&jumping==false&&getX()>=50) 
        {
            jumping=true;
            velY=-5;
            setImage(jump);
        }
        if(jumping==true)
            jump();
        death();
    }    
    
    /**
     * This method makes the object to jump to the left.
     */
    public void jump()
    {
        if(getY()<=230)
          velY=-velY;
        if(velY>0&&getY()>=330)
        { 
            velY=0;  
            jumping=false;
            setImage(stand);
        }
        setLocation(getX()-1,getY()+velY);
    }
    
    /**
     * Method to remove the object after it has been hitted twice with the weapon axe or once with the weapon 
     * sword.
     */
    public void death()
    {
        if(isTouching(Weapon.class))
        {
            if(isTouching(Sword.class)) vulnerable=true;
            if(vulnerable==true)
            {
             getWorld().removeObject(getOneIntersectingObject(Axe.class));
             getWorld().removeObject(this);
             
             setIsDeath(true);
            }else
            {
                vulnerable=true;
                getWorld().removeObject(getOneIntersectingObject(Axe.class));
            }
        }
    }
    
}
